﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace DarwinIsDead.Bullets {
    /// <summary>
    /// Basic Bullet class.
    /// </summary>
    /// </remarks>
    public class TBullet : Bullet {
        // Sprite
        private Texture2D sprite;
        // Color
        private Color color;
        // Movement speed;
        private float speed;
        private float range;
        private float distance;
        private bool getin = true;

        public TBullet(World world, bool friendly, int damage)
            : base(world, 16f, 16f, friendly, damage) {
            sprite = World.Game.Content.Load<Texture2D>("Sprites\\Bullets\\sprSharkTooth");
            
            color = Color.White;
            speed = 100f;   // Moves 800 pixels per second
            range = 500f;   // But dissipates within 500 pixels
        }

        public override void Collision(Entity other, Rectangle overlap) {
            // You can use this to determine how much a penetration power a
            // bullet has, among other things.  This one stops as soon as it
            // hits something.
            if ((!Friendly && other is Player) ||
                (Friendly && other is Zombie)) {
                Active = false;
                distance = 0f;
            }
        }

        public override void Fire(Vector2 position, float angle) {
            MouseState Ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            int vpw = World.Game.GraphicsDevice.Viewport.Width;
            int vph = World.Game.GraphicsDevice.Viewport.Height;
            
            Vector2 np = new Vector2();
            np.X = (Ms.X - (World.Camera.Position.X - vpw / 2.0f));
            np.Y = (Ms.Y - (World.Camera.Position.Y - vph / 2.0f));

            Position = np;
        }

        protected override void InternalUpdate(GameTime gameTime) {            
            // Handle dissipation over distance
            distance += 5f;
            if (distance > range) {
                Active = false;
                distance = 0f;
            }
        }

        protected override void InternalDraw(SpriteBatch spriteBatch) {
            //spriteBatch.Draw(sprite, Position, null, Color.White, 0f, Vector2.Zero, /*(1/distance) * 200*/ 2f, SpriteEffects.None, 0f);
            spriteBatch.Draw(sprite, Position, null, Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f);
        }
    }
}
